package com.stu.day02;

/**
 * 不使用中间量交换ab的值
 * @author zy
 * @date 2025/1/23 20:47
 */
public class ExchangeDemo {
    static int a = 10;
    static int b = 20;
    public static void main(String[] args) {
        a = b^(b = a)^a;   //交换a和b的值
        System.out.println("a: "+a);  //20
        System.out.println("b: "+b);  //10

        a = a^b;  //交换a和b的值(方式二)
        b = a^b;
        a = a^b;
        System.out.println("a: "+a);  //10
        System.out.println("b: "+b);  //20
    }
}
